//
// Created by 29439 on 2025/1/26.
//

#include "MyTest.h"
#include "Person.pb.h"

void MyTest::test() {
    // 序列化
    personSpace::Person p;
    p.set_id(10);
    p.set_age(32);
    p.set_sex("man");

    p.add_name();
    p.set_name(0, "lbz");
    p.add_name("jjl");
    p.add_name("zsf");

    p.mutable_addr()->set_addr("山东省枣庄市");
    p.mutable_addr()->set_num(1700);

    p.set_color(personSpace::Color::Blue);

    // 序列化对象p，最终得到1个字符串
    std::string output;
    p.SerializeToString(&output);

    // 反序列化数据
    personSpace::Person p2;
    p2.ParseFromString(output);
    std::cout << p2.id() << ", " << p2.age() << ", " << p2.sex() << std::endl;
    std::cout << p2.addr().addr() << ", " << p2.addr().num() << std::endl;
    int size = p.name_size();
    for (int i = 0; i < size; i++) {
        std::cout << p.name(i) << " ";
    }
    std::cout << std::endl;
    std::cout << p2.color() << std::endl;
}
